<!DOCTYPE html>
<html lang="en">
<style>
	/*.main-content{
		background: url("../../../Public/background/lw.jpg");
		background-repeat: no-repeat;
		background-size: 100% 100%;
	}*/
	#upload_img object{height: 140px;width: 180px;}
</style>
<include file="Index:head"/>
	<div class="main-container" id="main-container">
		<div class="main-content">
			<!-- <div style="clear: both;"></div> -->
				<div class="row" style="margin-top: 50px;">
					<div class="col-xs-12">
						<div class="form-horizontal user_form" role="form" id="uid">
							<div class="form-group">
								<label class="col-sm-3 control-label no-padding-right" for="form-field-1">  <span style="color: red;">*(必填)</span> 用户账号</label>
								
								<div class="col-sm-9">
									<input type="text" id="form-field-1" placeholder="用户账号" class="col-xs-10 col-sm-5" name="username" value="<{$user.username}>">
								</div>
							
							</div>
							<div class="form-group">
								<label class="col-sm-3 control-label no-padding-right" for="form-field-1">  <span style="color: red;">*(必填)</span> 密码 </label>

								<div class="col-sm-9">
									<input type="text"
										   <php>
											   if($_GET['admin_id'])
											   echo "readonly";
										   </php>
										   id="form-field-2" placeholder="密码" class="col-xs-10 col-sm-5" name="password">
								</div>
							</div>
							<div class="form-group">
								<label class="col-sm-3 control-label no-padding-right" for="form-field-1">  <span style="color: red;">*(必填)</span> 权限分配 </label>

								<div class="col-sm-8" id="auth">
									<foreach name="auth" item="m">
									<div class="col-sm-3 control-group">
										<label class="control-label bolder blue"><{$m.name}></label>
										<div class="checkbox" style="display: <php>
											if(count($m['menu']) == 0)
											echo 'block;';
											else
											echo 'none;';
										</php>;">
											<label>
												<input class="ace ace-switch ace-switch-6" type="checkbox" name="<{$m.action}>"
												<php>
													if($m['show'] === true)
													echo "checked";
												</php>
												>
												<span class="lbl">&nbsp;<{$m.name}></span>
											</label>
										</div>
										<foreach name="m['menu']" item="me">
										<div class="checkbox" style="display: <php>
											if(count($m['menu']) == 0)
											echo 'none;';
											else
											echo 'block;';
										</php>;">
											<label>
												<input class="ace ace-switch ace-switch-6" type="checkbox" name="<{$me.action}>"
												<php>
													if($me['show'] === true)
													echo "checked";
												</php>
												>
												<span class="lbl">&nbsp;<{$me.name}></span>
											</label>
										</div>
										</foreach>
									</div>
									</foreach>
								</div>
							</div>
						</div><!--表单组-->
						<div class="clearfix form-actions">
							<div class="col-sm-offset-3 col-sm-9">
								<button class="btn btn-info updateuser" type="button" id="tijiao"
								<php>
									if(isset($_GET['admin_id']))
									echo "style='display:none;'";
								</php>>
									<i class="icon-ok bigger-110"></i>
									创建
								</button>
								<button name="<php>echo $_GET['admin_id']</php>" class="btn btn-danger updateuser" type="button" id="update"
								<php>
									if(!isset($_GET['admin_id']))
									echo "style='display:none;'";
								</php>>
									<i class="icon-pencil bigger-110"></i>
									更新
								</button>
							</div>
						</div>
					</div><!--col-xs-12-->
				</div><!--row-->
			</div><!--page-content-->
		</div>
	</div>
<include file="Index:footer"/>
<!--自己的js代码引入-->
		<script type="text/javascript">
			$("#tijiao").click(function () {
				var ipt = $("#auth [type=checkbox]:checked");
				var auth = [];
				var username = $("[name=username]").val();
				var password = $("[name=password]").val();
				$.each(ipt,function (k,v) {
					auth.push($(v).attr("name"));
				});
				var url = root+"/admin/admin/addAdmin";
				$.post(url,{username:username,password:password,auth:JSON.stringify(auth)},function (res) {
					if(res.status){
						return dialog.success(res.info,function () {
							var index = parent.layer.getFrameIndex(window.name); //先得到当前iframe层的索引
							parent.location.reload();
							parent.layer.close(index); //再执行关闭
						});
					}else{
						return dialog.error(res.info);
					}
				});
			});
			$("#update").click(function () {
				var ipt = $("#auth [type=checkbox]:checked");
				var auth = [];
				var admin_id = $(this).attr("name");
				var password = $("[name=password]").val();
				$.each(ipt,function (k,v) {
					auth.push($(v).attr("name"));
				});
				var url = root+"/admin/admin/updateAdmin";
				$.post(url,{admin_id:admin_id,password:password,auth:JSON.stringify(auth)},function (res) {
					if(res.status){
						return dialog.success(res.info,function () {
							var index = parent.layer.getFrameIndex(window.name); //先得到当前iframe层的索引
							parent.location.reload();
							parent.layer.close(index); //再执行关闭
						});
					}else{
						return dialog.error(res.info);
					}
				});
			})
		</script>
</html>